package ccpc_2024;

import java.util.*;

public class I {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int n = sc.nextInt();
        Set<String> set = new HashSet<>();
        for(int i=0; i<n; i++)  set.add(sc.next().toLowerCase());
        String[] arr = s.split(" ");
        for(int i = 0; i<arr.length; i++){
            if(arr[i].charAt(arr[i].length() - 1) == ',' || arr[i].charAt(arr[i].length()-1) == '.' || arr[i].charAt(arr[i].length()-1) == '?' || arr[i].charAt(arr[i].length()-1) == '!' ){
                arr[i] = arr[i].substring(0, arr[i].length()-1);
            }
            arr[i] = arr[i].toLowerCase();
        }
        int ans = 0;
        for(String s1:arr) {
            if(s1.length() == 0) continue;
            if(!set.contains(s1)) {
                ans++;
                set.add(s1);
            }
        }
        System.out.println(ans);
    }
}
